package web.suzy.oj.dao.discussion.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import web.suzy.oj.dao.discussion.DiscussionEntityService;
import web.suzy.oj.dao.msg.MsgRemindEntityService;
import web.suzy.oj.mapper.DiscussionMapper;
import web.suzy.oj.pojo.entity.discussion.Discussion;
import web.suzy.oj.pojo.entity.msg.MsgRemind;
import web.suzy.oj.pojo.vo.DiscussionVO;

import javax.annotation.Resource;

/**
 * YangSuzy 软件工作室
 * 类名: DiscussionEntityServiceImpl
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/27 15:07
 */
@Service
public class DiscussionEntityServiceImpl extends ServiceImpl<DiscussionMapper, Discussion> implements DiscussionEntityService {
    @Autowired
    private DiscussionMapper discussionMapper;

    @Resource
    private MsgRemindEntityService msgRemindEntityService;

    /**
     * 方法名: getDiscussion
     * 描述: 获取讨论内容
     *
     * @param did 讨论ID
     * @param uid 用户ID 判断该用户是否给该条讨论点过赞
     * @return web.suzy.oj.pojo.vo.DiscussionVO
     * @date 2022/11/27 15:07
     * @auther YangSuzy
     **/
    @Override
    public DiscussionVO getDiscussion(Integer did, String uid) {
        return discussionMapper.getDiscussion(did, uid);
    }

    /**
     * 方法名: updatePostLikeMsg
     * 描述: 异步方法 - 更新讨论的点赞信息
     *
     * @param recipientId  接收方ID
     * @param senderId     发送方ID
     * @param discussionId 讨论ID
     * @return void
     * @date 2022/11/27 15:11
     * @auther YangSuzy
     **/
    @Async
    @Override
    public void updatePostLikeMsg(String recipientId, String senderId, Integer discussionId) {
        //新建消息提醒对象
        MsgRemind msgRemind = new MsgRemind();
        //设置操作类型：点赞
        msgRemind.setAction("Like_Post")
                //设置接收方ID
                .setRecipientId(recipientId)
                //设置发送方ID
                .setSenderId(senderId)
                //设置消息来源：被点赞的讨论ID
                .setSourceId(discussionId)
                //设置事件源类型：讨论
                .setSourceType("Discussion")
                //设置发生操作的url
                .setUrl("/discussion-detail/" + discussionId);
        //保存消息提示
        msgRemindEntityService.saveOrUpdate(msgRemind);
    }
}
